package common

import (
	"log"
)

// Arith 定义服务类型
type Arith int

// Multiply 服务类型的方法
func (t *Arith) Multiply(args *ArithArgs, reply *int) error {
	*reply = args.A * args.B
	log.Println("arguments:", args)
	return nil
}

// ArithArgs 方法参数
type ArithArgs struct {
	A, B int
}

type Mock struct {
	DIR     string
	PKG     string
	VERSION string
	RELEASE string
	SRC_TAR string
}

type Args struct {
	Cmd     string
	WorkDir string
	Pkg     string
	Version string
	Release string
	SrcTar  string
}

func (mock *Mock) Init(args *Args) {
	//后面要对mock使用反射传入环境变量
	mock.DIR = args.WorkDir
	mock.PKG = args.Pkg
	mock.VERSION = args.Version
	mock.RELEASE = args.Release
	mock.SRC_TAR = args.SrcTar
}

func (mock *Mock) Call(args *Args, reply *string) error {
	//TODO: 每次RPC都会拷贝args，考虑调用init方法只拷贝一次
	mock.Init(args)
	switch args.Cmd {
	case "sources":
		{
			return MakeRun(mock, "server", "sources")
		}
	case "spec":
		{
			return spec(mock)
		}
	case "srpm":
		{
			return MakeRun(mock, "server", "srpm")
		}
	case "upload":
		{
			return MakeRun(mock, "server", "upload")
		}
	}
	*reply = "success"
	return nil
}
